home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 April / macformat-049.iso / mac / Shareware Plus / Developers / dropg++ / usr / include / sys / proc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  10.2 KB  |  264 lines  |  [TEXT/R*ch]

  1. /*-
  2.  * Copyright (c) 1986, 1989, 1991, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  * (c) UNIX System Laboratories, Inc.
  5.  * All or some portions of this file are derived from material licensed
  6.  * to the University of California by American Telephone and Telegraph
  7.  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  8.  * the permission of UNIX System Laboratories, Inc.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    @(#)proc.h    8.8 (Berkeley) 1/21/94
  39.  */
  40.  
  41. #ifndef _SYS_PROC_H_
  42. #define    _SYS_PROC_H_
  43.  
  44. #include <machine/proc.h>        /* Machine-dependent proc substruct. */
  45. #include <sys/select.h>            /* For struct selinfo. */
  46.  
  47. /*
  48.  * One structure allocated per session.
  49.  */
  50. struct    session {
  51.     int    s_count;        /* Ref cnt; pgrps in session. */
  52.     struct    proc *s_leader;        /* Session leader. */
  53.     struct    vnode *s_ttyvp;        /* Vnode of controlling terminal. */
  54.     struct    tty *s_ttyp;        /* Controlling terminal. */
  55.     char    s_login[MAXLOGNAME];    /* Setlogin() name. */
  56. };
  57.  
  58. /*
  59.  * One structure allocated per process group.
  60.  */
  61. struct    pgrp {
  62.     struct    pgrp *pg_hforw;        /* Forward link in hash bucket. */
  63.     struct    proc *pg_mem;        /* Pointer to pgrp members. */
  64.     struct    session *pg_session;    /* Pointer to session. */
  65.     pid_t    pg_id;            /* Pgrp id. */
  66.     int    pg_jobc;    /* # procs qualifying pgrp for job control */
  67. };
  68.  
  69. /*
  70.  * Description of a process.
  71.  *
  72.  * This structure contains the information needed to manage a thread of
  73.  * control, known in UN*X as a process; it has references to substructures
  74.  * containing descriptions of things that the process uses, but may share
  75.  * with related processes.  The process structure and the substructures
  76.  * are always addressible except for those marked "(PROC ONLY)" below,
  77.  * which might be addressible only on a processor on which the process
  78.  * is running.
  79.  */
  80. struct    proc {
  81.     struct    proc *p_forw;        /* Doubly-linked run/sleep queue. */
  82.     struct    proc *p_back;
  83.     struct    proc *p_next;        /* Linked list of active procs */
  84.     struct    proc **p_prev;        /*    and zombies. */
  85.  
  86.     /* substructures: */
  87.     struct    pcred *p_cred;        /* Process owner's identity. */
  88.     struct    filedesc *p_fd;        /* Ptr to open files structure. */
  89.     struct    pstats *p_stats;    /* Accounting/statistics (PROC ONLY). */
  90.     struct    plimit *p_limit;    /* Process limits. */
  91.     struct    vmspace *p_vmspace;    /* Address space. */
  92.     struct    sigacts *p_sigacts;    /* Signal actions, state (PROC ONLY). */
  93.  
  94. #define    p_ucred        p_cred->pc_ucred
  95. #define    p_rlimit    p_limit->pl_rlimit
  96.  
  97.     int    p_flag;            /* P_* flags. */
  98.     char    p_stat;            /* S* process status. */
  99.     char    p_pad1[3];
  100.  
  101.     pid_t    p_pid;            /* Process identifier. */
  102.     struct    proc *p_hash;     /* Hashed based on p_pid for kill+exit+... */
  103.     struct    proc *p_pgrpnxt; /* Pointer to next process in process group. */
  104.     struct    proc *p_pptr;     /* Pointer to process structure of parent. */
  105.     struct    proc *p_osptr;     /* Pointer to older sibling processes. */
  106.  
  107. /* The following fields are all zeroed upon creation in fork. */
  108. #define    p_startzero    p_ysptr
  109.     struct    proc *p_ysptr;     /* Pointer to younger siblings. */
  110.     struct    proc *p_cptr;     /* Pointer to youngest living child. */
  111.     pid_t    p_oppid;     /* Save parent pid during ptrace. XXX */
  112.     int    p_dupfd;     /* Sideways return value from fdopen. XXX */
  113.  
  114.     /* scheduling */
  115.     u_int    p_estcpu;     /* Time averaged value of p_cpticks. */
  116.     int    p_cpticks;     /* Ticks of cpu time. */
  117.     fixpt_t    p_pctcpu;     /* %cpu for this process during p_swtime */
  118.     void    *p_wchan;     /* Sleep address. */
  119.     char    *p_wmesg;     /* Reason for sleep. */
  120.     u_int    p_swtime;     /* Time swapped in or out. */
  121.     u_int    p_slptime;     /* Time since last blocked. */
  122.  
  123.     struct    itimerval p_realtimer;    /* Alarm timer. */
  124.     struct    timeval p_rtime;    /* Real time. */
  125.     u_quad_t p_uticks;        /* Statclock hits in user mode. */
  126.     u_quad_t p_sticks;        /* Statclock hits in system mode. */
  127.     u_quad_t p_iticks;        /* Statclock hits processing intr. */
  128.  
  129.     int    p_traceflag;        /* Kernel trace points. */
  130.     struct    vnode *p_tracep;    /* Trace to vnode. */
  131.  
  132.     int    p_siglist;        /* Signals arrived but not delivered. */
  133.  
  134.     struct    vnode *p_textvp;    /* Vnode of executable. */
  135.  
  136.     long    p_spare[5];        /* pad to 256, avoid shifting eproc. */
  137.  
  138. /* End area that is zeroed on creation. */
  139. #define    p_endzero    p_startcopy
  140.  
  141. /* The following fields are all copied upon creation in fork. */
  142. #define    p_startcopy    p_sigmask
  143.  
  144.     sigset_t p_sigmask;    /* Current signal mask. */
  145.     sigset_t p_sigignore;    /* Signals being ignored. */
  146.     sigset_t p_sigcatch;    /* Signals being caught by user. */
  147.  
  148.     u_char    p_priority;    /* Process priority. */
  149.     u_char    p_usrpri;    /* User-priority based on p_cpu and p_nice. */
  150.     char    p_nice;        /* Process "nice" value. */
  151.     char    p_comm[MAXCOMLEN+1];
  152.  
  153.     struct     pgrp *p_pgrp;    /* Pointer to process group. */
  154.  
  155. /* End area that is copied on creation. */
  156. #define    p_endcopy    p_thread
  157.     int    p_thread;    /* Id for this "thread"; Mach glue. XXX */
  158.     struct    user *p_addr;    /* Kernel virtual addr of u-area (PROC ONLY). */
  159.     struct    mdproc p_md;    /* Any machine-dependent fields. */
  160.  
  161.     u_short    p_xstat;    /* Exit status for wait; also stop signal. */
  162.     u_short    p_acflag;    /* Accounting flags. */
  163.     struct    rusage *p_ru;    /* Exit information. XXX */
  164.  
  165. };
  166.  
  167. #define    p_session    p_pgrp->pg_session
  168. #define    p_pgid        p_pgrp->pg_id
  169.  
  170. /* Status values. */
  171. #define    SIDL    1        /* Process being created by fork. */
  172. #define    SRUN    2        /* Currently runnable. */
  173. #define    SSLEEP    3        /* Sleeping on an address. */
  174. #define    SSTOP    4        /* Process debugging or suspension. */
  175. #define    SZOMB    5        /* Awaiting collection by parent. */
  176.  
  177. /* These flags are kept in p_flags. */
  178. #define    P_ADVLOCK    0x00001    /* Process may hold a POSIX advisory lock. */
  179. #define    P_CONTROLT    0x00002    /* Has a controlling terminal. */
  180. #define    P_INMEM        0x00004    /* Loaded into memory. */
  181. #define    P_NOCLDSTOP    0x00008    /* No SIGCHLD when children stop. */
  182. #define    P_PPWAIT    0x00010    /* Parent is waiting for child to exec/exit. */
  183. #define    P_PROFIL    0x00020    /* Has started profiling. */
  184. #define    P_SELECT    0x00040    /* Selecting; wakeup/waiting danger. */
  185. #define    P_SINTR        0x00080    /* Sleep is interruptible. */
  186. #define    P_SUGID        0x00100    /* Had set id privileges since last exec. */
  187. #define    P_SYSTEM    0x00200    /* System proc: no sigs, stats or swapping. */
  188. #define    P_TIMEOUT    0x00400    /* Timing out during sleep. */
  189. #define    P_TRACED    0x00800    /* Debugged process being traced. */
  190. #define    P_WAITED    0x01000    /* Debugging process has waited for child. */
  191. #define    P_WEXIT        0x02000    /* Working on exiting. */
  192. #define P_EXEC        0x04000    /* Process called exec. */
  193.  
  194. /* Should probably be changed into a hold count. */
  195. #define    P_NOSWAP    0x08000    /* Another flag to prevent swap out. */
  196. #define    P_PHYSIO    0x10000    /* Doing physical I/O. */
  197.  
  198. /* Should be moved to machine-dependent areas. */
  199. #define    P_OWEUPC    0x20000    /* Owe process an addupc() call at next ast. */
  200.  
  201. /*
  202.  * MOVE TO ucred.h?
  203.  *
  204.  * Shareable process credentials (always resident).  This includes a reference
  205.  * to the current user credentials as well as real and saved ids that may be
  206.  * used to change ids.
  207.  */
  208. struct    pcred {
  209.     struct    ucred *pc_ucred;    /* Current credentials. */
  210.     uid_t    p_ruid;            /* Real user id. */
  211.     uid_t    p_svuid;        /* Saved effective user id. */
  212.     gid_t    p_rgid;            /* Real group id. */
  213.     gid_t    p_svgid;        /* Saved effective group id. */
  214.     int    p_refcnt;        /* Number of references. */
  215. };
  216.  
  217. #ifdef KERNEL
  218. /*
  219.  * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
  220.  * as it is used to represent "no process group".
  221.  */
  222. #define    PID_MAX        30000
  223. #define    NO_PID        30001
  224. #define    PIDHASH(pid)    ((pid) & pidhashmask)
  225.  
  226. #define SESS_LEADER(p)    ((p)->p_session->s_leader == (p))
  227. #define    SESSHOLD(s)    ((s)->s_count++)
  228. #define    SESSRELE(s) {                            \
  229.     if (--(s)->s_count == 0)                    \
  230.         FREE(s, M_SESSION);                    \
  231. }
  232.  
  233. extern struct proc *pidhash[];        /* In param.c. */
  234. extern struct pgrp *pgrphash[];        /* In param.c. */
  235. extern struct proc *curproc;        /* Current running proc. */
  236. extern struct proc proc0;        /* Process slot for swapper. */
  237. extern int nprocs, maxproc;        /* Current and max number of procs. */
  238. extern int pidhashmask;            /* In param.c. */
  239.  
  240. volatile struct proc *allproc;         /* List of active procs. */
  241. struct proc *zombproc;            /* List of zombie procs. */
  242. struct proc *initproc, *pageproc;    /* Process slots for init, pager. */
  243.  
  244. #define    NQS    32            /* 32 run queues. */
  245. int    whichqs;            /* Bit mask summary of non-empty Q's. */
  246. struct    prochd {
  247.     struct    proc *ph_link;        /* Linked list of running processes. */
  248.     struct    proc *ph_rlink;
  249. } qs[NQS];
  250.  
  251. struct proc *pfind __P((pid_t));    /* Find process by id. */
  252. struct pgrp *pgfind __P((pid_t));    /* Find process group by id. */
  253.  
  254. void    mi_switch __P((void));
  255. void    resetpriority __P((struct proc *));
  256. void    setrunnable __P((struct proc *));
  257. void    setrunqueue __P((struct proc *));
  258. void    sleep __P((void *chan, int pri));
  259. int    tsleep __P((void *chan, int pri, char *wmesg, int timo));
  260. void    unsleep __P((struct proc *));
  261. void    wakeup __P((void *chan));
  262. #endif    /* KERNEL */
  263. #endif    /* !_SYS_PROC_H_ */
  264.